package com.wangshang.team.commodity.dao;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.wangshang.team.commodity.po.TeamCommodities;
import com.wangshang.team.commodity.po.TeamCommoditiesId;

/**
 * A data access object (DAO) providing persistence and search support for
 * TeamCommodities entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see com.wangshang.team.commodity.po.TeamCommodities
 * @author MyEclipse Persistence Tools
 */

public class TeamCommoditiesDAO extends HibernateDaoSupport {
	private static final Log log = LogFactory.getLog(TeamCommoditiesDAO.class);
	// property constants
	public static final String NUM_OF_COMMODITY = "numOfCommodity";
	public static final String COMMODITY_NAME = "commodityName";
	public static final String PLACE_ID = "placeId";
	public static final String PLACE_MASK = "placeMask";
	public static final String DELIVERY_REQ = "deliveryReq";
	public static final String SPECIAL_REQ = "specialReq";
	public static final String SPECIAL_ATTRIB_SEL = "specialAttribSel";
	public static final String COMMODITY_NORM = "commodityNorm";

	protected void initDao() {
		// do nothing
	}

	public void save(TeamCommodities transientInstance) {
		log.debug("saving TeamCommodities instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(TeamCommodities persistentInstance) {
		log.debug("deleting TeamCommodities instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public TeamCommodities findById(
			com.wangshang.team.commodity.po.TeamCommoditiesId id) {
		log.debug("getting TeamCommodities instance with id: " + id);
		try {
			TeamCommodities instance = (TeamCommodities) getHibernateTemplate()
					.get("com.wangshang.team.commodity.TeamCommodities", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(TeamCommodities instance) {
		log.debug("finding TeamCommodities instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding TeamCommodities instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from TeamCommodities as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByNumOfCommodity(Object numOfCommodity) {
		return findByProperty(NUM_OF_COMMODITY, numOfCommodity);
	}

	public List findByCommodityName(Object commodityName) {
		return findByProperty(COMMODITY_NAME, commodityName);
	}

	public List findByPlaceId(Object placeId) {
		return findByProperty(PLACE_ID, placeId);
	}

	public List findByPlaceMask(Object placeMask) {
		return findByProperty(PLACE_MASK, placeMask);
	}

	public List findByDeliveryReq(Object deliveryReq) {
		return findByProperty(DELIVERY_REQ, deliveryReq);
	}

	public List findBySpecialReq(Object specialReq) {
		return findByProperty(SPECIAL_REQ, specialReq);
	}

	public List findBySpecialAttribSel(Object specialAttribSel) {
		return findByProperty(SPECIAL_ATTRIB_SEL, specialAttribSel);
	}

	public List findByCommodityNorm(Object commodityNorm) {
		return findByProperty(COMMODITY_NORM, commodityNorm);
	}

	public List findAll() {
		log.debug("finding all TeamCommodities instances");
		try {
			String queryString = "from TeamCommodities";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public TeamCommodities merge(TeamCommodities detachedInstance) {
		log.debug("merging TeamCommodities instance");
		try {
			TeamCommodities result = (TeamCommodities) getHibernateTemplate()
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(TeamCommodities instance) {
		log.debug("attaching dirty TeamCommodities instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(TeamCommodities instance) {
		log.debug("attaching clean TeamCommodities instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static TeamCommoditiesDAO getFromApplicationContext(
			ApplicationContext ctx) {
		return (TeamCommoditiesDAO) ctx.getBean("TeamCommoditiesDAO");
	}
}